import urllib.request
import re
pagenum = 306 #开始页码
x = 0
while pagenum >= 258: #下到第几页
    page = str(pagenum)
    res = urllib.request.urlopen("http://jandan.net/ooxx/page-"+page+"#comments")
    ret = res.read()
    ret = ret.decode('utf-8')
    m = re.findall(r'<div class="text">.*?</a></span><p><a href="//(.*?)" target',ret,re.S)
    pagenum -= 1
    for imgurl in m:
        spec = imgurl[-3:]
        urllib.request.urlretrieve("http://"+imgurl, 'E:\图片\爬虫\%s.'% x+spec )
        x += 1
